#ifndef CLCOMFILEPARSER_H
#define CLCOMFILEPARSER_H

#include <QtCore/qglobal.h>
#include <vector>
#include <string>
#include <string.h>
#include "CLComLibrarys_global.h"
//CLCOMLIBRARYS_EXPORT

using namespace std;

typedef const char* XMLFILE;
typedef const char* XMLTREE;

enum FM_VALUE_TYPE
{
    FM_VALUE_TYPE_NO = 0,
    FM_VALUE_TYPE_INT,
    FM_VALUE_TYPE_DOUBLE,
    FM_VALUE_TYPE_CHARS,
};
enum FM_RET_VALUE
{
    FM_RET_PARAMETER_ERROR = -1,
    FM_RET_VALUE_FALSE = 0,
    FM_RET_VALUE_OK,
};
enum FM_CAD_FILE_TYPE
{
    FM_CAD_FILE_TYPE_NO = 0,
    FM_CAD_FILE_TYPE_CSV,
    FM_CAD_FILE_TYPE_TXT,
    FM_CAD_FILE_TYPE_CAD
};

#define F_ID_LEN 32
#define F_XML_VALUE_LEN 256
#define F_XML_NAME_LEN 64
#define F_XML_ATTR_LEN 256

#define FM_FILE_INVALID(TFILE) (0 != strlen(TFILE))

typedef struct CLCOMLIBRARYS_EXPORT _tagXMLNodeInfo
{
    FM_VALUE_TYPE useType;
    int nValue;
    double dValue;
    char czValue[F_XML_VALUE_LEN];

    char czName[F_XML_NAME_LEN];
    char czAttribute[F_XML_ATTR_LEN];

    char czID[F_ID_LEN];

    _tagXMLNodeInfo()
    {
        memset((void*)this, 0, sizeof(_tagXMLNodeInfo));
    }
    _tagXMLNodeInfo(const _tagXMLNodeInfo& other)
    {
        memcpy((void*)this, (void*)&other, sizeof(_tagXMLNodeInfo));
    }
    _tagXMLNodeInfo& operator=(const _tagXMLNodeInfo& other)
    {
        memcpy((void*)this, (void*)&other, sizeof(_tagXMLNodeInfo));
        return *this;
    }

}XMLNODEINFO, *PXMLNODEINFO;

/////////////////////////////////begin:file///////////////////////////////////
typedef struct CLCOMLIBRARYS_EXPORT _tagCADColumnLine
{
    int nLineCount;
    int nColumnCount;

    _tagCADColumnLine()
    {
        memset((void*)this, 0, sizeof(_tagCADColumnLine));
    }
    _tagCADColumnLine(const _tagCADColumnLine& other)
    {
        memcpy((void*)this, (void*)&other, sizeof(_tagCADColumnLine));
    }
    _tagCADColumnLine& operator=(const _tagCADColumnLine& other)
    {
        memcpy((void*)this, (void*)&other, sizeof(_tagCADColumnLine));

        return *this;
    }
}CADCOLUMNLINE, *PCADCOLUMNLINE;

typedef struct CLCOMLIBRARYS_EXPORT _tagCADValueInfo
{
    int nValue;
    double dValue;
    char czValue[F_XML_VALUE_LEN];
    _tagCADValueInfo()
    {
        memset((void*)this, 0, sizeof(_tagCADValueInfo));
    }
    _tagCADValueInfo(const _tagCADValueInfo& other)
    {
        memcpy((void*)this, (void*)&other, sizeof(_tagCADValueInfo));
    }
    _tagCADValueInfo& operator=(const _tagCADValueInfo& other)
    {
        memcpy((void*)this, (void*)&other, sizeof(_tagCADValueInfo));

        return *this;
    }
}CADVALUEINFO, *PCADVALUEINFO;

class CLCOMLIBRARYS_EXPORT CLComFileParser
{
public:
    /*CreateInstance单例模式，多次调用都是同一对象，ppicl对象地址的指针*/
    static CLComFileParser* GetInstance();
    /*ReleaseInstance释放*/
    static bool ReleaseInstance(CLComFileParser* pIcl);
    /*GetErrorCode获取错误码*/
    static int GetErrorCode();
public:
    /*begin:xml*/
    //打开xml文件，bcreate如果不存在是否创建
    virtual int XMLCreateFile(const char* filename, char* czID) = 0;
    virtual int XMLOpenFile(const char* fileName, char* czID) = 0;

    virtual int XMLGetNodeByFile(XMLFILE inFile, const char* nodeName, char* czID) = 0;
    virtual int XMLGetNodeByFatherNode(XMLFILE inFile, XMLTREE pFathertree, const char* childNodeName, char* czID) = 0;

    virtual int XMLGetValue(XMLFILE pFile, const char* aName, XMLNODEINFO& outinfo) = 0;
    virtual int XMLSetNodeValue(XMLFILE pFile, const char*  aName, XMLNODEINFO& ininfo) = 0;
    virtual int XMLGetNodeInfo(XMLFILE inFile, XMLTREE ptree, XMLNODEINFO& value) = 0;
    virtual int XMLSetNodeValueEx(XMLFILE inFile, XMLTREE ptree, XMLNODEINFO& value) = 0;
    virtual int XMLDelNode(XMLFILE inFile, XMLTREE ptree) = 0;
    virtual int XMLAddNode(XMLFILE inFile, XMLTREE pFathertree, XMLNODEINFO& value) = 0;

    virtual int XMLGetFahterNode(XMLFILE inFile, XMLTREE pChildtree, char* czID) = 0;

    virtual int XMLGetChildNodes(XMLFILE inFile, XMLTREE ptree, vector<string>& list) = 0;

    virtual int XMLGetRootNode(XMLFILE inFile, char* czID) = 0;

    virtual int XMLSaveXMLFile(XMLFILE inFile) = 0;

    virtual void XMLCloseFile(XMLFILE inFile) = 0;

    ///扩展xml操作
    virtual int XMLGetNodeValueEx(XMLFILE pFile, const char*  fathernodename, const char*  nodename, XMLNODEINFO& outinfo) = 0;
    ///扩展xml操作
    virtual int XMLSetNodeValueEx(XMLFILE pFile, const char*  fathernodename, const char*  nodename, XMLNODEINFO& outinfo) = 0;


    virtual int XMLModifyNodeAttribute(XMLFILE pFile, XMLTREE ptree, const char* attributeName, const char* attributeValue) = 0;
    /*end:xml*/

    /*begin:SELF FILE*/
    virtual int SELFFCreateFile(const char* inFilename, char* czID, bool bCreate) = 0;
    virtual void SELFFCLOSEFile(const char* fid) = 0;
    virtual bool SELFFBFileValid(const char* fid) = 0;
    virtual int SELFFReadFile(const char* fid, void* readContent, int contentLen) = 0;
    virtual int SELFFReadLine(const char* fid, void* readcontent, int contentLen) = 0;
    virtual bool SELFFReadOver(const char* fid) = 0;
    virtual int SELFFRWriteFile(const char* fid, void* writeStr, int nWriteSize) = 0;
    virtual int SELFFAppendWriteFile(const char* fid, void* writeStr, int nWriteSize) = 0;
    virtual void SELFFSetEncrypt(const char* fid, bool bEncrypt) = 0;
    virtual void SELFFSetFileName(const char* fid, const char* filename) = 0;
    virtual void SELFFGetFileName(const char* fid, char* outfilename, int nBuffersize) = 0;
    virtual int SELFFGetFileSize(const char* fid) = 0;
    /*begin:SELF FILE*/

    /*begin:cad*/
    virtual int CADCreateFile(const char* inFilename, char* czID) = 0;
    virtual int CADOpenFile(const char* inFileName, char* czID) = 0;
    virtual int CADGetColumns(const char* fid, CADCOLUMNLINE& outLineColumn) = 0;
    virtual int CADGetData(const char* fid, CADCOLUMNLINE& inLineColumn, FM_VALUE_TYPE inType, CADVALUEINFO& outValue) = 0;

    virtual int CADAddData(const char* fid, CADCOLUMNLINE& inLineColumn, FM_VALUE_TYPE inType, CADVALUEINFO Value) = 0;

    virtual void CADCloseFile(const char* fid) = 0;
    virtual int CADSaveFile(const char* fid, const char* filename) = 0;
    /*end:cad*/
};

#endif // CLCOMFILEPARSER_H
